package com.ph.demo.JDKcurrent;

import sun.util.locale.LanguageTag;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 先执行副线程  在执行主线程
 */
public class CountDownLatchDemo implements Runnable{

    public static final CountDownLatch latch = new CountDownLatch(10);

    public static final CountDownLatchDemo demo = new CountDownLatchDemo();

    @Override
    public void run() {

        try {
            Thread.sleep(new Random().nextInt(10)*1000);
            System.out.println("complete");
            latch.countDown();
        } catch (InterruptedException e) {
             e.printStackTrace();
        }

    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        for (int i = 0; i < 10; i++) {
            executorService.submit(demo);
            executorService.execute(demo);
        }

        latch.await();

        System.out.println("fire");

        executorService.shutdown();


    }
}
